//
//  ViewController.swift
//  ForgettingCurve
//
//  Created by chenxu on 16/9/18.
//  Copyright © 2016年 chenxu. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
//        originalResult()
        stringResult()
    }

    func originalResult() -> [NSObject]{
        let wordN = 42 // 单元数
        let intervalArr = [0, 1, 2, 4, 7, 15] // 复习间隔
        let dayN = wordN + intervalArr.last! // 复习天数
        var arrM : [NSObject] = []
        for i in 1...dayN{
            var dayArr  = [i]
            for j in intervalArr{
                let m = i - j
                if m > 0 && m <= wordN {
                    dayArr.append(m)
                }
            }
            arrM.append(dayArr)
        }
        print(arrM)
        let filePath:String = "/Users/chenxu/Desktop/单词记忆曲线.txt"
        let arrOC = arrM as NSArray
        arrOC.writeToFile(filePath, atomically: true)

        return arrM
    }
    
    func stringResult() -> [String]{
        let wordN = 42 // 单元数
        let intervalArr = [0, 1, 2, 4, 7, 15] // 复习间隔
        let dayN = wordN + intervalArr.last! // 复习天数
        var arrM = [String]()
        for i in 1...dayN{
            var dayStr  = "第\(i)天："
            for j in intervalArr{
                let m = i - j
                if m > 0 && m <= wordN {
                    dayStr = dayStr + "\(m),"
                }
            }
            arrM.append(dayStr)
        }
//        print(arrM)
        let filePath:String = "/Users/chenxu/Desktop/单词记忆曲线.txt"
        let arrOC = arrM as NSArray
        arrOC.writeToFile(filePath, atomically: true)
        
        return arrM
    }
}

